﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace APIDataManage.XmlToDB
{
    public class DstnCntryBsXml
    {
        public void insertDstCntryBsToDB(string type_search="", string srh_ope="")
        {
            APIDataFunction api = new APIDataFunction();
            XmlDocument doc = api.getDestinationsCountriesBases(type_search, srh_ope);
            if(doc != null)
            {
                XmlElement root = doc.DocumentElement;
                StringBuilder sb = new StringBuilder();

                string strCreatedDate = DateTime.Now.ToString("yyyy-MM-dd");

                foreach (XmlNode node in root.ChildNodes)
                {
                    sb.AppendFormat("insert into Destination (id_dest, Value, createdDate) values({0},'{1}','{2}');", 
                        node.Attributes["id_dest"].Value, node.Attributes["name"].Value, strCreatedDate);

                    //foreach(XmlNode childNode_lvl1 in node)
                    //{
                    //    sb.AppendFormat("insert into country values();", childNode_lvl1["id_country"].Value, childNode_lvl1["name"].Value);
                    //}
                }

                if (sb.Length > 0)
                {
                    SqlDbHelper.ExecteNonQuery(sb.ToString(), null);
                }
            }
        }
    }
}
